<?php

  /*

      TravianWAP
      Copyright (c) 2007-08 by Ananas - All rights reserved
      http://n00bz.biz/travianwap/
      Contact: uroskn@gmail.com

      --------------------------------------------------------------------------

      This program is free software: you can redistribute it and/or modify
      it under the terms of the GNU  General Public License as published by
      the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU  General Public License
      along with this program. If not, see http://www.gnu.org/licenses/.

  */

  $name = substr($text, strpos($text, '<h1><b>') + 7);
  $name = substr($name, 0, strpos($name, '</b>'));

  echo "<strong>$name</strong><br/>";

  $info = travian_return_troop_upgrade_info($text, $req["id"], True);
  
  function mimplode($array, $glue = ' ', $final = '<br/>')
  {
    $count = count($array);
    if ((!is_array($array)) || ($count == 0)) return '';
    else
    {
      $end = pdate(array_pop($array));
      if($count > 1) return implode($glue, $array).$final.$end;
      else return $end;
    }
  }

  if (count($info["train"]) > 1)
  {
    for ($i = 0; $i < count($info["train"]); $i++)
    {
      echo "<br/>{$info["train"][$i]["name"]}";
      if (!empty($info["train"][$i]["level"])) echo " [{$info["train"][$i]["level"]}]";
      echo "<br/>".mimplode($info["train"][$i]["requires"], ' ', '<br/>');
      if (!empty($info["train"][$i]["error"])) echo "<br/>".$info["train"][$i]["error"];
      else
      {
        echo " ";
        print_link("main.php?mod=direct_call&amp;file=".
                   "build&amp;".htmlspecialchars($info["train"][$i]["link"]).
                   "&amp;return=details_build".ps(), "Upgrade");
      }
      echo "<br/>";
    }
  }
  else echo "Nothing to research.<br/>";

  if (!empty($info["atrain"]))
  {
    echo "<br/><strong>Active research</strong><br/>{$info["atrain"]["name"]}<br/>".
          pdate($info["atrain"]["remain"])."<br/>".pdate($info["atrain"]["at"])."<br/>";
  }

  echo "<br/>";

?>
